﻿using System.Xml.Linq;
using Engine;
using Game;


public class MoreWidget : CanvasWidget
{
    public ComponentPlayer m_componentPlayer;

    public SubsystemNK m_subsystemHL;

    public ComponentMiner componentMiner;

    public SubsystemTime subsystemTime;

    public Game.Random random = new Game.Random();

    public ComponentShop m_componentShop;

    public ButtonWidget m_moreButton;
    public ButtonWidget m_more4Button;
    public ButtonWidget m_more5Button;
    public ButtonWidget m_more6Button;
    public ButtonWidget m_more7Button;
    public SubsystemGameInfo m_subsystemGameInfo;
    //下面是新人物状态按钮系统
    public MoreWidget(ComponentPlayer componentPlayer, SubsystemNK subsystemHL, ComponentShop componentShop)
    {
        m_componentPlayer = componentPlayer;
        m_subsystemHL = subsystemHL;
        m_componentShop = componentShop;

        XElement node = ContentManager.Get<XElement>("Widgets/gd");
        LoadContents(this, node);
        m_moreButton = Children.Find<ButtonWidget>("moreButton");
        m_more4Button = Children.Find<ButtonWidget>("more4Button");
        m_more5Button = Children.Find<ButtonWidget>("more5Button");
        m_more6Button = Children.Find<ButtonWidget>("more6Button");
        m_more7Button = Children.Find<ButtonWidget>("more7Button");
    }


    public override void Update()
    {
        NK9 hL = m_componentPlayer.Entity.FindComponent<NK9>();
        int activeBlockValue = m_componentPlayer.ComponentMiner.ActiveBlockValue;
        int num66 = Terrain.ExtractContents(activeBlockValue);
        float FH = m_componentPlayer.ComponentHealth.FireResilience;
        float ZH = m_componentPlayer.ComponentBody.Mass;
        float XLU = m_componentPlayer.ComponentHealth.FallResilience;
        float XL2 = m_componentPlayer.ComponentHealth.m_lastHealth * m_componentPlayer.ComponentHealth.AttackResilience;
        float XL = m_componentPlayer.ComponentHealth.AttackResilience;
        float Water = hL.Water * 100;
        string XYZ = m_componentPlayer.ComponentBody.Position.X + "  ,  " + m_componentPlayer.ComponentBody.Position.Y + "  ,  " + m_componentPlayer.ComponentBody.Position.Z;
        string XYZ2 = m_componentPlayer.PlayerData.SpawnPosition.X + "  ,  " + m_componentPlayer.PlayerData.SpawnPosition.Y + "  ,  " + m_componentPlayer.PlayerData.SpawnPosition.Z;

        string xiuwei = (m_componentPlayer.PlayerData.Level < 5) ? "0阶下" : (m_componentPlayer.PlayerData.Level >= 5 && m_componentPlayer.PlayerData.Level < 10) ? "0阶上" : (m_componentPlayer.PlayerData.Level >= 10 && m_componentPlayer.PlayerData.Level < 13) ? "1阶下" : (m_componentPlayer.PlayerData.Level >= 13 && m_componentPlayer.PlayerData.Level < 16) ? "1阶上" : (m_componentPlayer.PlayerData.Level >= 16 && m_componentPlayer.PlayerData.Level < 20) ? "1阶满" : (m_componentPlayer.PlayerData.Level >= 20 && m_componentPlayer.PlayerData.Level < 24) ? "2阶下" : (m_componentPlayer.PlayerData.Level >= 24 && m_componentPlayer.PlayerData.Level < 28) ? "2阶上" : (m_componentPlayer.PlayerData.Level >= 28 && m_componentPlayer.PlayerData.Level < 30) ? "2阶满" : (m_componentPlayer.PlayerData.Level >= 30 && m_componentPlayer.PlayerData.Level < 33) ? "3阶下" : (m_componentPlayer.PlayerData.Level >= 33 && m_componentPlayer.PlayerData.Level < 36) ? "3阶上" : (m_componentPlayer.PlayerData.Level >= 36 && m_componentPlayer.PlayerData.Level < 39) ? "3阶狂暴" : (m_componentPlayer.PlayerData.Level >= 39 && m_componentPlayer.PlayerData.Level < 42) ? "4阶下" : (m_componentPlayer.PlayerData.Level >= 42 && m_componentPlayer.PlayerData.Level < 46) ? "4阶上" : (m_componentPlayer.PlayerData.Level >= 46 && m_componentPlayer.PlayerData.Level < 50) ? "4阶高级" : (m_componentPlayer.PlayerData.Level >= 50 && m_componentPlayer.PlayerData.Level < 54) ? "5阶下" : (m_componentPlayer.PlayerData.Level >= 54 && m_componentPlayer.PlayerData.Level < 58) ? "5阶上" : (m_componentPlayer.PlayerData.Level >= 58 && m_componentPlayer.PlayerData.Level < 60) ? "6阶灭世" : (m_componentPlayer.PlayerData.Level >= 60 && m_componentPlayer.PlayerData.Level < 65) ? "6阶顶级" : (m_componentPlayer.PlayerData.Level >= 65 && m_componentPlayer.PlayerData.Level < 70) ? "神阶下世" : (m_componentPlayer.PlayerData.Level >= 70 && m_componentPlayer.PlayerData.Level < 90) ? "神阶灭世" : (m_componentPlayer.PlayerData.Level >= 90) ? "幻神" : "";
        if (m_moreButton.IsClicked)
        {
            m_componentPlayer.ComponentGui.DisplayLargeMessage("你的属性:", "阶段:" + xiuwei + "\n" + "血量上限:" + XL + "\n" + "当前血量:" + XL2 + "\n" + "内法:" + Water + "\n" + "摔落免疫:" + XLU + "\n" + "防火免疫:" + FH + "\n" + "重量:" + ZH, 5f, 0f);
               	          
        }
        if (m_more4Button.IsClicked)
        {
            m_componentPlayer.ComponentGui.DisplaySmallMessage("余额：" + m_subsystemHL.Money + "$", new Color(255, 0, 0), blinking: true, playNotificationSound: false);
            m_componentPlayer.ComponentGui.ModalPanelWidget = new ShopWidget(m_componentPlayer.Entity.FindComponent<ComponentShop>(), m_componentPlayer, m_subsystemHL);
        }
        if (m_more5Button.IsClicked)
        {
            m_componentPlayer.ComponentGui.DisplaySmallMessage("当前人物坐标:" + XYZ, new Color(255, 0, 0), blinking: true, playNotificationSound: false);
        }
        if (m_more6Button.IsClicked)
        {
            m_componentPlayer.ComponentGui.DisplaySmallMessage("人物出生点坐标:" + XYZ2, new Color(255, 0, 0), blinking: true, playNotificationSound: false);
        }
        if (m_more7Button.IsClicked)
        {
            m_subsystemHL.Money -= 10f;
            int XJ = (new Game.Random()).Int(1, 8);
            if (XJ == 1)
            {
                m_componentPlayer.ComponentGui.DisplaySmallMessage("谢谢惠顾", new Color(255, 0, 0), blinking: true, playNotificationSound: false);
            }
            if (XJ == 2)
            {
                m_componentPlayer.ComponentGui.DisplaySmallMessage("抽奖游戏：+1$", new Color(255, 0, 0), blinking: true, playNotificationSound: false);
                m_subsystemHL.Money += 1f;
            }
            if (XJ == 3)
            {
                m_componentPlayer.ComponentGui.DisplaySmallMessage("抽奖游戏：+10$", new Color(255, 0, 0), blinking: true, playNotificationSound: false);
                m_subsystemHL.Money += 10f;
            }
            if (XJ == 4)
            {
                m_componentPlayer.ComponentGui.DisplaySmallMessage("你摔了一跤，但是+20$，......", new Color(255, 0, 0), blinking: true, playNotificationSound: false);
                m_subsystemHL.Money += 20f;
                if (m_componentPlayer.ComponentHealth.Health > 0.3f)
                {
                    m_componentPlayer.ComponentHealth.Health -= 0.1f;
                }
            }
            if (XJ == 5)
            {
                m_componentPlayer.ComponentGui.DisplaySmallMessage("你摔了一大跤，但是+30$，......", new Color(255, 0, 0), blinking: true, playNotificationSound: false);
                m_subsystemHL.Money += 30f;
                if (m_componentPlayer.ComponentHealth.Health > 0.3f)
                {
                    m_componentPlayer.ComponentHealth.Health -= 0.4f;
                }
            }
            if (XJ == 6 && m_subsystemHL.Money >= 10f)
            {
                m_componentPlayer.ComponentGui.DisplaySmallMessage("没什么理由扣你血，但是-10$，祝你好运.......", new Color(255, 0, 0), blinking: true, playNotificationSound: false);
                m_subsystemHL.Money -= 10f;
            }
            if (XJ == 7)
            {
                m_componentPlayer.ComponentGui.DisplaySmallMessage("你玩了几局游戏，但是连胜10把\n因此你去当了代打，并赚了点钱，但是身体...了\n祝你好运.......", new Color(255, 0, 0), blinking: true, playNotificationSound: false);
                m_subsystemHL.Money += 10f;
                if (m_componentPlayer.ComponentHealth.Health > 0.3f)
                {
                    m_componentPlayer.ComponentHealth.Health -= 0.1f;
                }
            }
            if (XJ == 8 && m_subsystemHL.Money >= 40f)
            {
                m_componentPlayer.ComponentGui.DisplaySmallMessage("你玩了一把游戏，但是连输了10把\n因此充了40$请了代打，祝你好运.......", new Color(255, 0, 0), blinking: true, playNotificationSound: false);
                m_subsystemHL.Money -= 40f;
                if (m_componentPlayer.ComponentHealth.Health > 0.3f)
                {
                    m_componentPlayer.ComponentHealth.Health -= 0.2f;
                }
            }
        }
    }
}
